<template>
	<view class="content" :style="{ height: windowHeight + 'px' }">
		<view class="title">
			评价：{{name}}
		</view>
		<u--form :model="model1" :rules="rules" ref="uForm" labelWidth="140">
			<u-form-item label="评价等级" prop="reviewGrade">
				<u-rate :count="count" v-model="model1.reviewGrade" :allowHalf="true" :size="size"></u-rate>
			</u-form-item>
			<u-form-item label="申请原因" prop="reviewContent">
				<u--textarea v-model="model1.reviewContent" maxlength="-1" clearable height="160"></u--textarea>
			</u-form-item>
			<view class="flex">
				<view class="image-title">图片</view>
				<UpLoad :fileList="model1.reviewImage" name="1" multiple :maxCount="5"
					@onChange="(value) => { model1.reviewImage = value }" :place="'图最多可以上传5张'" />
			</view>
		</u--form>
		<view class="buttons" @click="submits">
			提交评价
		</view>


	</view>
</template>

<script>
	import UpLoad from '../../components/upLoad/index.vue'
	import {
		systemInfo
	} from '../../utils/mixin'
	import {
		getDicts,
		addCircle,
		updateMallRecord
	} from '@/api/index.js'
	export default {
		components: {
			UpLoad
		},
		mixins: [systemInfo],
		data() {
			return {
				id: '',
				name: '',
				count: 5,
				size: 26,
				model1: {
					reviewContent: '',
					reviewGrade: undefined,
					reviewImage: ''
				},
				rules: {
					reviewGrade: [{
						type: 'number',
						required: true,
						message: '请选择评价等级',
						trigger: ['blur', 'change']
					}],
					reviewContent: [{
						type: 'string',
						required: true,
						message: '请输入评价内容',
						trigger: ['blur', 'change']
					}]
				}
			}
		},
		async onLoad(options) {
			// 状态栏高度
			this.getSystemInfo();

			// 记录id
			this.id = options.id
			this.name = options.name

		},
		methods: {
			submits() {
				this.$refs.uForm.validate().then(async (valid) => {
					if (valid) {
						if (!this.model1.reviewImage) {
							uni.$u.toast("请上传图片")
						} else {
							this.model1.reviewImage = this.model1.reviewImage.split(',').map(item => '/' +
								item).join(',')
							await updateMallRecord({
								...this.model1,
								id: this.id,
								status: 4
							})
							uni.$u.toast("评价成功")
							await uni.navigateTo({
								url: '/subpackage3/order/order',
								success: function(e) {
									uni.$emit('templateClick')
								}
							});

						}
					}
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.content {
		background-color: #fff;
		width: 100%;
		box-sizing: border-box;
		padding: 40rpx;

		/deep/ .u-textarea {
			background-color: rgb(245, 247, 250);
		}

		.buttons {
			margin: 50rpx auto 0;
			width: 300rpx;
			height: 80rpx;
			background-color: rgba(34, 175, 229);
			color: #fff;
			line-height: 80rpx;
			text-align: center;
			font-size: 36rpx;
			border-radius: 10rpx;
			letter-spacing: 20rpx;
		}

		.flex {
			display: flex;
			align-items: center;
			margin-top: 20rpx;

			.image-title {
				width: 140rpx;
			}
		}
	}
</style>